package com.iflytek.jcy.supervise.job.component.config;

import ch.qos.logback.access.tomcat.LogbackValve;
import org.apache.catalina.startup.Tomcat;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 输出tomcat access日志
 *
 * @author <a href=mailto:ktyi@iflytek.com>伊开堂</a>
 * @date 2021/6/30
 */
@Configuration
public class AccessLogConfig {

    @Bean
    @ConditionalOnClass(Tomcat.class)
    public TomcatServletWebServerFactory serverFactoryCustomizer() {
        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
        LogbackValve logbackValve = new LogbackValve();
        logbackValve.setFilename("logback-access.xml");
        tomcat.addContextValves(logbackValve);
        return tomcat;
    }

}
